package com.qiyuexinxi.chat.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiyuexinxi.chat.domain.UserNew;
import com.qiyuexinxi.chat.domain.UserRecommend;
import com.qiyuexinxi.chat.dto.request.GetUserInfoRequest;
import com.qiyuexinxi.chat.dto.request.GetUserListRequest;
import com.qiyuexinxi.chat.dto.response.GetUserInfoResponse;
import com.qiyuexinxi.chat.dto.response.GetUserListResponse;
import com.qiyuexinxi.chat.mapper.UserActiveMapper;
import com.qiyuexinxi.chat.mapper.UserNewMapper;
import com.qiyuexinxi.chat.service.UserNewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yangxingyu
 * @date 2020/3/28
 * @description
 */
@Service
public class UserNewServiceImpl implements UserNewService {
    @Autowired
    UserNewMapper userNewMapper;
    @Autowired
    UserServiceImpl userService;
    @Override
    public GetUserListResponse getUserNew(GetUserListRequest getUserListRequest) {
        PageHelper.startPage(getUserListRequest.getPage(), getUserListRequest.getSize());
        GetUserListResponse getUserListResponse = new GetUserListResponse();
        List<GetUserInfoResponse> getUserInfoResponses = new ArrayList<GetUserInfoResponse>();
        List<UserNew> userNews = userNewMapper.getUserNew(getUserListRequest.getSex());
        PageInfo<UserNew> pageInfo = new PageInfo<UserNew>(userNews);
        for (UserNew userNew : pageInfo.getList()) {
            getUserInfoResponses.add(userService.getUserInfoVo(userNew.getUserId()));
        }
        getUserListResponse.setUserInfoList(getUserInfoResponses);
        getUserListResponse.setTotalNum(pageInfo.getTotal() + "");
        getUserListResponse.setHasNextPage(pageInfo.isHasNextPage());
        return getUserListResponse;
    }
}
